package com.project.harmonyledger.controller;

import com.project.harmonyledger.common.response.Result;
import com.project.harmonyledger.dto.AccountBalanceParams;
import com.project.harmonyledger.dto.AccountParams;
import com.project.harmonyledger.pojo.Account;
import com.project.harmonyledger.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/accounts")
public class AccountController {
  @Autowired
  private AccountService accountService;

  @PostMapping("/create")
  public Result<Map<String, String>> createAccount(@RequestBody AccountParams params) {
    Account account = new Account();
    account.setAccountTypeId(params.getAccountTypeId());
    account.setName(params.getName());
    account.setBalance(params.getBalance());
    return accountService.createAccount(account);
  }

  @GetMapping("/getUserAccounts")
  public Result<List<Account>> getUserAccounts(@RequestParam String userId) {
    return accountService.getUserAccounts(userId);
  }

  @GetMapping("/getAccountById")
  public Result<Map<String, String>> getAccountById(@RequestParam Long id) {
    return accountService.getAccountById(id);
  }

  @PutMapping("/updateBalance")
  public Result<Map<String, String>> updateBalance(@RequestBody AccountBalanceParams params) {
    return accountService.updateBalance(params.getAccountId(), params.getAmount());
  }

  @GetMapping("/getAccountSummary")
  public Result<Map<String, String>> getAccountSummary(@RequestParam Long id) {
    return accountService.getAccountSummary(id);
  }
}